import java.util.Calendar;

public class Arrival {
	private int stopID;
	private int routeID;
	private String destination;
	private long predictedDepartureTime;
	private long scheduledDepartureTime;
	private boolean predicted;
	@SuppressWarnings("unused")
	private int vehicleID;
	
	// 0 = scheduled, 1 = on time, 2 = late, 3 = early
	private int onTimeStatus;
	private int minutesUntilArrival;
	
	
	public int getRouteID() {
		return routeID;
	}

	public void setRouteID(int routeID) {
		this.routeID = routeID;
	}

	public String getDestination() {
		return destination;
	}

	public void setDestination(String destination) {
		this.destination = destination;
	}

	public int getOnTimeStatus() {
		return onTimeStatus;
	}

	public void setOnTimeStatus(int onTimeStatus) {
		this.onTimeStatus = onTimeStatus;
	}

	public int getMinutesUntilArrival() {
		return minutesUntilArrival;
	}

	public void setMinutesUntilArrival(int minutesUntilArrival) {
		this.minutesUntilArrival = minutesUntilArrival;
	}
	
	public Arrival(int stopID2, String routeID2, String destination2,
			String predictedDepartureTime2, String scheduledDepartureTime2,
			String predicted2) {
		// TODO Auto-generated constructor stub
		this.stopID = stopID2;
		this.routeID = Integer.parseInt(routeID2);
		this.destination = destination2;
		this.predictedDepartureTime = Long.parseLong(predictedDepartureTime2);
		this.scheduledDepartureTime = Long.parseLong(scheduledDepartureTime2);
		this.predicted = Boolean.parseBoolean(predicted2);
		
		if (!predicted)
			onTimeStatus = 0;
		else if (Math.abs(scheduledDepartureTime - predictedDepartureTime) <= 60000 )
			onTimeStatus = 1;
		else if (scheduledDepartureTime - predictedDepartureTime < 0)
			onTimeStatus = 2;
		else
			onTimeStatus = 3;
		
		// TODO Calculate minutes until arrival
		if(predicted) {
			Calendar rightNow = Calendar.getInstance();
			long msToArrival = this.predictedDepartureTime - rightNow.getTimeInMillis();
			this.minutesUntilArrival = (int)Math.ceil((msToArrival / 60000));
		} else {
			Calendar rightNow = Calendar.getInstance();
			long msToArrival = this.scheduledDepartureTime - rightNow.getTimeInMillis();
			this.minutesUntilArrival = (int)Math.ceil((msToArrival / 60000));
		}
			
	}
	
	public String toString(){
		return "stopID=" + stopID + ",routeID=" + routeID + ",destination=" + destination + 
			",predictedDepartureTime=" + predictedDepartureTime + ",scheduledDepartureTime=" + scheduledDepartureTime
			+ ",predicted=" + predicted;
	}
	
	
}
